import { defineStore } from "pinia";
import type { TCount } from "./type";

const useCounterStore = defineStore("counter", {
  persist: true,
  state: (): TCount => ({
    num: 0,
  }),
  getters: {
    doublueCount: (state) => state.num * 2,
  },
  actions: {
    increment() {
      this.num++;
    },
    decrement() {
      this.num--;
    },
    async asyncIncrement() {
      await new Promise((resolve) => setTimeout(resolve, 1000));
      this.increment();
    },
    async asyncDecrement() {
      await new Promise((resolve) => setTimeout(resolve, 1000));
      this.decrement();
    },
  },
});

export default useCounterStore;
